/**
 * 
 */
package due.pc.pcshoot.entity;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.util.MathUtils;

import due.pc.pcshoot.control.Objektiv;

import android.content.Context;
import android.util.Log;

/**
 * @author manhhung.vu
 *
 */
public class Canon extends Sprite
{
	//===============================================================/
	//Constants
	//===============================================================/
	public static final String CANON_IMAGEPATH = "gfx/fed_turret_auto_v1.png";
	public static final int CANON_WIDTH = 128;
	public static final int CANON_HEIGHT = 128;
	
	public static final int CANON_SHOTS_DEFAULTAMONG = 5;
	
	//===============================================================/
	//Fields
	//===============================================================/
	private int mShotAmong = CANON_SHOTS_DEFAULTAMONG;
	
	//===============================================================/
	//Constructors
	//===============================================================/
	public Canon(float pX, float pY, TextureRegion pTextureRegion) {
		super(pX, pY, pTextureRegion);
	}
	
	//===============================================================/
	//Inherited Methods
	//===============================================================/
	
	
	//===============================================================/
	//Methods
	//===============================================================/

	
	//===============================================================/
	//Getters & Setters
	//===============================================================/
	public float[] getFirePoint() {
		return convertLocalToSceneCoordinates(CANON_WIDTH / 2, 0);
	}
	
	
	public int getShotAmong() {
		return mShotAmong;
	}
	
	public void setShotAmong(int pShotAmong) {
		this.mShotAmong = pShotAmong;
	}
	
	public void addShot(int pAmong) {
		mShotAmong += pAmong;
	}
	
	public boolean isShootable() {
		return mShotAmong > 0;
	}
	
	public void decreaseShotAmong() 
	{
		mShotAmong--;
		if (mShotAmong < 0) mShotAmong = 0;
	}
	
	//===============================================================/
	//Static Methods
	//===============================================================/
	public static Canon createCanon(float pX, float pY, Engine pEngine, Context pContext)
	{
		Texture canonTexture = new Texture(128, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		TextureRegion canonTextureRegion = TextureRegionFactory.createFromAsset(
				canonTexture, pContext, CANON_IMAGEPATH, 0, 0);
		pEngine.getTextureManager().loadTexture(canonTexture);
		
		Canon canon = new Canon(pX, pY, canonTextureRegion);
		
		return canon;
	}
	
	//===============================================================/
	//Inner Classes
	//===============================================================/
}
